import axios from "axios"
import nProgress from "nprogress"
import "nprogress/nprogress.css"
const request = axios.create({
    baseURL:process.env.VUE_APP_MOCKAPI,
    timeout:9999
})
request.interceptors.request.use(
    (config)=>{
        nProgress.start();
        return config
    },
    (error)=>{
        nProgress.done();
        return Promise.reject(error.message)
    }
)
request.interceptors.response.use(
    (response)=>{
        nProgress.done();
        if( response.data.code==200){
            return response.data.data
        }else{
            //否则返回一个错误的信息
            return Promise.reject({message:response.data.message})
        }
    },
    (error)=>{
        nProgress.done();
        return Promise.reject(error.message)
    }
)
export default  request